package test;

/**
 * Test gc  memory
 */

import com.huonan.utils.ExecutorUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;

/**
 * MOFT Test
 */
@Slf4j
public class MOFT {
    public static void main(String[] args) {
        ExecutorService threadPool = ExecutorUtil.getExecutorService(3);
        CompletableFuture.runAsync(() -> {
            ArrayList<Object> list = new ArrayList<>();
            try {
                while (true) {
                    list.add(new Object());
                }

            } catch (OutOfMemoryError e) {
                log.info("对象大小:{}", list.size());
                log.error("内存溢出异常:{}", e.getMessage());
            }
        }, threadPool);
        ExecutorUtil.closePool(threadPool);
    }
}